package com.eduspace.eduplatform.wares.utils;

import lombok.Builder;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

/**
 * @author tbc on 2017/5/22 12:39:57.
 */
@Slf4j
@Builder
@Data
public class ResultWrapper {
    private String requestId;
    private String code;
    private String httpCode = "200";
    private String message;

    private Object result;

    public static ResultWrapper ok(Object result) {
        return ResultWrapper.builder()
                .code("200")
                .httpCode("200")
                .message("")
                .requestId("")
                .result(result)
                .build();
    }

    public static ResultWrapper requestErr(String message) {
        return ResultWrapper.builder()
                .code("400")
                .httpCode("200")
                .message(message)
                .requestId("")
                .result("")
                .build();
    }

    public static ResultWrapper serverErr(String message) {
        return serverErr(message, "");
    }

    public static ResultWrapper serverErr(String message, Object result) {
        return ResultWrapper.builder()
                .code("500")
                .httpCode("200")
                .message(message)
                .requestId("")
                .result(result)
                .build();
    }

    public boolean ok() {
        return "200".equals(code);
    }

    public boolean noOk() {
        return !ok();
    }


}
